import 'package:flutter/material.dart';

class CustomerRadioList extends StatefulWidget {
  final List<String>? options;

  CustomerRadioList(this.options);

  @override
  State<CustomerRadioList> createState() => _CustomerRadioListState();
}

class _CustomerRadioListState extends State<CustomerRadioList> {
  List<bool>? optionsChecked = [];

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    if (widget.options != null && widget.options!.isNotEmpty) {
      optionsChecked = List<bool>.filled(widget.options!.length, false);
    }

    print(optionsChecked);
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: widget.options == null
              ? []
              : widget.options!.map((e) {
                  return GestureDetector(
                    onTap: (){
                      setState(() {
                        var preStatus =
                        optionsChecked![widget.options!.indexOf(e)];
                        optionsChecked!
                            .fillRange(0, optionsChecked!.length, false);
                        optionsChecked![widget.options!.indexOf(e)] = !preStatus;
                      });
                    },
                    child: Container(
                      height: 40,
                      decoration: BoxDecoration(
                          border:
                          Border(bottom: BorderSide(color: Colors.black12))),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Text(e),
                          if (optionsChecked![widget.options!.indexOf(e)])
                            Icon(
                              Icons.check,
                              size: 18,
                              color: Colors.blue,
                            )
                        ],
                      ),
                    ),
                  );
                }).toList()),
    );
  }
}

// GestureDetector(
// onTap: (){
// setState(() {
// var preStatus= optionsChecked![widget.options!.indexOf(e)];
// optionsChecked!.fillRange(0,  optionsChecked!.length,false);
// optionsChecked![widget.options!.indexOf(e)]=!preStatus;
// });
